///////////////////////////////////////////////////////////
//  SampleSourcesafe.cpp
//  Implementation of the Class SampleSourcesafe
//  Created on:      21-sep-2007 15:40:08
///////////////////////////////////////////////////////////

#include "SampleSourcesafe.h"
#include <iostream>

#define SIZE_PKSAMPLESOURCESAFE 10
#define SIZE_CODE 5
#define SIZE_ALTM 7
#define SIZE_DATE 11
#define SIZE_DEW 4
#define SIZE_DIR 4
#define SIZE_GUS 7
#define SIZE_HOUR 5
#define SIZE_RH 4
#define SIZE_SPD 4
#define SIZE_TMP 4
#define SIZE_VIS 5
#define SIZE_WEATHER 19

#define SIZE_PKSAMPLESOURCESAFE_SCHEMA 19
#define SIZE_CODE_SCHEMA 10
#define SIZE_ALTM_SCHEMA 5
#define SIZE_DATE_SCHEMA 5
#define SIZE_DEW_SCHEMA 4
#define SIZE_DIR_SCHEMA 4
#define SIZE_GUS_SCHEMA 4
#define SIZE_HOUR_SCHEMA 5
#define SIZE_RH_SCHEMA 3
#define SIZE_SPD_SCHEMA 4
#define SIZE_TMP_SCHEMA 4
#define SIZE_VIS_SCHEMA 4
#define SIZE_WEATHER_SCHEMA 8

campo SampleSourcesafe::PK[2] = {{"PKSampleSourcesafe",CHAR, SIZE_PKSAMPLESOURCESAFE},{0,0,0}};
campo SampleSourcesafe::CODE[2] = {{"stationCode",CHAR, SIZE_CODE},{0,0,0}};
campo SampleSourcesafe::ALTM[2] = {{"altm",CHAR, SIZE_ALTM},{0,0,0}};
campo SampleSourcesafe::DATE[2] = {{"date",CHAR, SIZE_DATE},{0,0,0}};
campo SampleSourcesafe::DEW[2] = {{"dew",CHAR, SIZE_DEW},{0,0,0}};
campo SampleSourcesafe::DIR[2] = {{"dir",CHAR, SIZE_DIR},{0,0,0}};
campo SampleSourcesafe::GUS[2] = {{"gus",CHAR, SIZE_GUS},{0,0,0}};
campo SampleSourcesafe::HOUR[2] = {{"hour",CHAR, SIZE_HOUR},{0,0,0}};
campo SampleSourcesafe::RH[2] = {{"rh",CHAR, SIZE_RH},{0,0,0}};
campo SampleSourcesafe::SPD[2] = {{"spd",CHAR, SIZE_SPD},{0,0,0}};
campo SampleSourcesafe::TMP[2] = {{"tmp",CHAR, SIZE_TMP},{0,0,0}};
campo SampleSourcesafe::VIS[2] = {{"vis",CHAR, SIZE_VIS},{0,0,0}};
campo SampleSourcesafe::WEATHER[2] = {{"weather",CHAR, SIZE_WEATHER},{0,0,0}};

campo SampleSourcesafe::SAMPLESOURCESAFE_SCHEMA[SIZE_SAMPLESOURCESAFE_SCHEMA] = {{"PKSampleSourcesafe",CHAR, SIZE_PKSAMPLESOURCESAFE}, {"stationCode",CHAR, SIZE_CODE}, {"altm",CHAR, SIZE_ALTM}, {"date",CHAR, SIZE_DATE}, {"dew",CHAR, SIZE_DEW}, {"dir",CHAR, SIZE_DIR}, {"gus",CHAR, SIZE_GUS}, {"hour",CHAR, SIZE_HOUR}, {"rh",CHAR, SIZE_RH}, {"spd",CHAR, SIZE_SPD}, {"tmp",CHAR, SIZE_TMP}, {"vis",CHAR, SIZE_VIS}, {"weather",CHAR, SIZE_WEATHER},{0,0,0}};

#ifndef UNO
	#define UNO 1
#endif

#ifndef ZERO
	#define ZERO 0
#endif

SampleSourcesafe::SampleSourcesafe(){

}


SampleSourcesafe::~SampleSourcesafe(){

}

int SampleSourcesafe::getSchemaSize(){
	return  SIZE_SAMPLESOURCESAFE_SCHEMA;
}

std::string SampleSourcesafe::getPKSampleSourcesafe()
{
	return this->PKSampleSourcesafe;
}

std::string SampleSourcesafe::getStationCode(void){
	return this->stationCode;
}

std::string SampleSourcesafe::getKey()
{
	return this->PKSampleSourcesafe;
}

void SampleSourcesafe::setKey(std::string key){
	this->PKSampleSourcesafe = key;
}

bool SampleSourcesafe::EsMayor(std::string atributte, Persistent *object)
{
	return (this->getValor(atributte) > object->getValor(atributte));
}

std::string SampleSourcesafe::getValor(std::string atribName){

	if (SampleSourcesafe::PK[0].nombre == atribName){
		return this->PKSampleSourcesafe;
	}
	if (SampleSourcesafe::CODE[0].nombre == atribName){
		return this->stationCode;
	}
	if (SampleSourcesafe::ALTM[0].nombre == atribName){
		return this->altm;
	}
	if (SampleSourcesafe::DATE[0].nombre == atribName){
		return this->date;
	}
	if (SampleSourcesafe::DEW[0].nombre == atribName){
		return this->dew;
	}
	if (SampleSourcesafe::DIR[0].nombre == atribName){
		return this->dir;
	}
	if (SampleSourcesafe::GUS[0].nombre == atribName){
		return this->gus;
	}
	if (SampleSourcesafe::HOUR[0].nombre == atribName){
		return this->hour;
	}
	if (SampleSourcesafe::RH[0].nombre == atribName){
		return this->rh;
	}
	if (SampleSourcesafe::SPD[0].nombre == atribName){
		return this->spd;
	}
	if (SampleSourcesafe::TMP[0].nombre == atribName){
		return this->tmp;
	}
	if (SampleSourcesafe::VIS[0].nombre == atribName){
		return this->vis;
	}
	if (SampleSourcesafe::WEATHER[0].nombre == atribName){
		return this->weather;
	}
	
	return "";
}

campo* SampleSourcesafe::getCampoPorAtrib(std::string atribName){

	if (SampleSourcesafe::CODE[0].nombre == atribName){
		return SampleSourcesafe::CODE;
	}
	if (SampleSourcesafe::ALTM[0].nombre == atribName){
		return SampleSourcesafe::ALTM;
	}
	if (SampleSourcesafe::DATE[0].nombre == atribName){
		return SampleSourcesafe::DATE;
	}
	if (SampleSourcesafe::DEW[0].nombre == atribName){
		return SampleSourcesafe::DEW;
	}
	if (SampleSourcesafe::DIR[0].nombre == atribName){
		return SampleSourcesafe::DIR;
	}
	if (SampleSourcesafe::GUS[0].nombre == atribName){
		return SampleSourcesafe::GUS;
	}
	if (SampleSourcesafe::HOUR[0].nombre == atribName){
		return SampleSourcesafe::HOUR;
	}
	if (SampleSourcesafe::RH[0].nombre == atribName){
		return SampleSourcesafe::RH;
	}
	if (SampleSourcesafe::SPD[0].nombre == atribName){
		return SampleSourcesafe::SPD;
	}
	if (SampleSourcesafe::TMP[0].nombre == atribName){
		return SampleSourcesafe::TMP;
	}
	if (SampleSourcesafe::VIS[0].nombre == atribName){
		return SampleSourcesafe::VIS;
	}
	if (SampleSourcesafe::WEATHER[0].nombre == atribName){
		return SampleSourcesafe::WEATHER;
	}
	
	return NULL;
}

void SampleSourcesafe::loadAtribFromNode(XMLNode* node){

	listaXML::const_iterator j = node->hijos.begin();
	std::string nombreNodo;
	for(;j != node->hijos.end() ;j++)
	{
		nombreNodo=(*j)->getNombre();
		if (nombreNodo == "date")
		{
			this->date = (*j)->getContenido();
		}
		else
		{
			if (nombreNodo == "hour")
			{
				this->hour = (*j)->getContenido();
			}
			else
			{
				if (nombreNodo == "altm")
				{
					this->altm = (*j)->getContenido();
				}
				else
				{
					if (nombreNodo == "dew")
					{
						this->dew = (*j)->getContenido();
					}
					else
					{
						if (nombreNodo == "dir")
						{
							this->dir = (*j)->getContenido();
						}	
						else
						{
							if (nombreNodo == "gus")
							{
								this->gus = (*j)->getContenido();
							}
							else
							{
								if (nombreNodo == "rh")
								{
									this->rh = (*j)->getContenido();
								}
								else
								{
									if (nombreNodo == "spd")
									{
										this->spd = (*j)->getContenido();
									}
									else
									{
										if (nombreNodo == "tmp")
										{
											this->tmp = (*j)->getContenido();
										}
										else
										{
											if (nombreNodo == "vis")
											{
												this->vis = (*j)->getContenido();
											}
											else
											{
												if (nombreNodo == "weather")
												{
													this->weather = (*j)->getContenido();
												}
											}
										}
									}
								}
							}
						}	
					}	
				}
			}
		}
	}
}

//setters
void SampleSourcesafe::setPKSampleSourcesafe(std::string pk)
{
	this->PKSampleSourcesafe = pk;
}

void SampleSourcesafe::setStationCode(std::string code){
	this->stationCode = code;
}

void SampleSourcesafe::setAltm(std::string a)
{
	altm=a;
}
void SampleSourcesafe::setDate(std::string d)
{
	date=d;
}
void SampleSourcesafe::setDew(std::string d)
{
	dew=d;
}
void SampleSourcesafe::setDir(std::string d)
{
	dir=d;
}
void SampleSourcesafe::setGus(std::string g)
{
	gus=g;
}
void SampleSourcesafe::setHour(std::string h)
{
	hour=h;
}
void SampleSourcesafe::setRh(std::string r)
{
	rh=r;
}
void SampleSourcesafe::setSpd(std::string s)
{
	spd=s;
}
void SampleSourcesafe::setTmp(std::string t)
{
	tmp=t;
}
void SampleSourcesafe::setVis(std::string v)
{
	vis=v;
}
void SampleSourcesafe::setWeather(std::string w)
{
	weather=w;
}
//getters
std::string SampleSourcesafe::getAltm()
{
	return altm;
}
std::string SampleSourcesafe::getDate()
{
	return date;
}
std::string SampleSourcesafe::getDew()
{
	return dew;
}
std::string SampleSourcesafe::getDir()
{
	return dir;
}
std::string SampleSourcesafe::getGus()
{
	return gus;
}
std::string SampleSourcesafe::getHour()
{
	return hour;
}
std::string SampleSourcesafe::getRh()
{
	return rh;
}
std::string SampleSourcesafe::getSpd()
{
	return spd;
}
std::string SampleSourcesafe::getTmp()
{
	return tmp;
}
std::string SampleSourcesafe::getVis()
{
	return vis;
}
std::string SampleSourcesafe::getWeather()
{
	return weather;
}

campo* SampleSourcesafe::getSchema()
{
	return SampleSourcesafe::SAMPLESOURCESAFE_SCHEMA;
}

campo* SampleSourcesafe::getPrimaryKey()
{
	return SampleSourcesafe::PK;
}

void SampleSourcesafe::loadRegistro(void* registro)
{
	campo* esquema = NULL;

	char ptrPKSampleSourcesafe[SIZE_PKSAMPLESOURCESAFE + UNO];
	char ptrStationCode[SIZE_CODE + UNO];
	char ptrAltm[SIZE_ALTM + UNO];
	char ptrDate[SIZE_DATE + UNO];
	char ptrDew[SIZE_DEW + UNO];
	char ptrDir[SIZE_DIR + UNO];
	char ptrGus[SIZE_GUS + UNO];
	char ptrHour[SIZE_HOUR + UNO];
	char ptrRh[SIZE_RH + UNO];
	char ptrSpd[SIZE_SPD + UNO];
	char ptrTmp[SIZE_TMP + UNO];
	char ptrVis[SIZE_VIS + UNO];
	char ptrWeather[SIZE_WEATHER + UNO];

	memset(ptrPKSampleSourcesafe, ZERO, SIZE_PKSAMPLESOURCESAFE + UNO);
	memset(ptrStationCode, ZERO, SIZE_CODE + UNO);
	memset(ptrAltm, ZERO, SIZE_ALTM + UNO);
	memset(ptrDate, ZERO, SIZE_DATE + UNO);
	memset(ptrDew, ZERO, SIZE_DEW + UNO);
	memset(ptrDir, ZERO, SIZE_DIR + UNO);
	memset(ptrGus, ZERO, SIZE_GUS + UNO);
	memset(ptrHour, ZERO, SIZE_HOUR + UNO);
	memset(ptrRh, ZERO, SIZE_RH + UNO);
	memset(ptrSpd, ZERO, SIZE_SPD + UNO);
	memset(ptrTmp, ZERO, SIZE_TMP + UNO);
	memset(ptrVis, ZERO, SIZE_VIS + UNO);
	memset(ptrWeather, ZERO, SIZE_WEATHER + UNO);

	esquema = this->getSchema();

	RecordHandler::REG_GET(registro, esquema, "PKSampleSourcesafe, stationCode, altm, date, dew, dir, gus, hour, rh, spd, tmp, vis, weather", ptrPKSampleSourcesafe, ptrStationCode, ptrAltm, ptrDate, ptrDew, ptrDir, ptrGus, ptrHour, ptrRh, ptrSpd, ptrTmp, ptrVis, ptrWeather);

	this->PKSampleSourcesafe.clear();
	this->PKSampleSourcesafe += ptrPKSampleSourcesafe;
	
	this->stationCode.clear();
	this->stationCode += ptrStationCode;
		
	this->altm.clear();
	this->altm += ptrAltm;

	this->date.clear();
	this->date += ptrDate;

	this->dew.clear();
	this->dew += ptrDew;

	this->dir.clear();
	this->dir += ptrDir;

	this->gus.clear();
	this->gus += ptrGus;

	this->hour.clear();
	this->hour += ptrHour;

	this->rh.clear();
	this->rh += ptrRh;

	this->spd.clear();
	this->spd += ptrSpd;

	this->tmp.clear();
	this->tmp += ptrTmp;

	this->vis.clear();
	this->vis += ptrVis;

	this->weather.clear();
	this->weather += ptrWeather;
}

void SampleSourcesafe::saveInRegistro(void* reg)
{
	campo* esquema = NULL;

	char ptrPKSampleSourcesafe[SIZE_PKSAMPLESOURCESAFE + UNO];
	char ptrStationCode[SIZE_CODE + UNO];
	char ptrAltm[SIZE_ALTM + UNO];
	char ptrDate[SIZE_DATE + UNO];
	char ptrDew[SIZE_DEW + UNO];
	char ptrDir[SIZE_DIR + UNO];
	char ptrGus[SIZE_GUS + UNO];
	char ptrHour[SIZE_HOUR + UNO];
	char ptrRh[SIZE_RH + UNO];
	char ptrSpd[SIZE_SPD + UNO];
	char ptrTmp[SIZE_TMP + UNO];
	char ptrVis[SIZE_VIS + UNO];
	char ptrWeather[SIZE_WEATHER + UNO];

	memset(ptrPKSampleSourcesafe, ZERO, SIZE_PKSAMPLESOURCESAFE + UNO);
	memset(ptrStationCode, ZERO, SIZE_CODE + UNO);
	memset(ptrAltm, ZERO, SIZE_ALTM + UNO);
	memset(ptrDate, ZERO, SIZE_DATE + UNO);
	memset(ptrDew, ZERO, SIZE_DEW + UNO);
	memset(ptrDir, ZERO, SIZE_DIR + UNO);
	memset(ptrGus, ZERO, SIZE_GUS + UNO);
	memset(ptrHour, ZERO, SIZE_HOUR + UNO);
	memset(ptrRh, ZERO, SIZE_RH + UNO);
	memset(ptrSpd, ZERO, SIZE_SPD + UNO);
	memset(ptrTmp, ZERO, SIZE_TMP + UNO);
	memset(ptrVis, ZERO, SIZE_VIS + UNO);
	memset(ptrWeather, ZERO, SIZE_WEATHER + UNO);
	
	
	strncpy(ptrPKSampleSourcesafe, (char*)this->PKSampleSourcesafe.c_str(), SIZE_PKSAMPLESOURCESAFE);
	strncpy(ptrStationCode, (char*)this->stationCode.c_str(), SIZE_CODE);
	strncpy(ptrAltm, (char*)this->altm.c_str(), SIZE_ALTM);
	strncpy(ptrDate, (char*)this->date.c_str(), SIZE_DATE);
	strncpy(ptrDew, (char*)this->dew.c_str(), SIZE_DEW);
	strncpy(ptrDir, (char*)this->dir.c_str(), SIZE_DIR);
	strncpy(ptrGus, (char*)this->gus.c_str(), SIZE_GUS);
	strncpy(ptrHour, (char*)this->hour.c_str(), SIZE_HOUR);
	strncpy(ptrRh, (char*)this->rh.c_str(), SIZE_RH);
	strncpy(ptrSpd, (char*)this->spd.c_str(), SIZE_SPD);
	strncpy(ptrTmp, (char*)this->tmp.c_str(), SIZE_TMP);
	strncpy(ptrVis, (char*)this->vis.c_str(), SIZE_VIS);
	strncpy(ptrWeather, (char*)this->weather.c_str(), SIZE_WEATHER);

	esquema = this->getSchema();

	RecordHandler::REG_SET(reg, esquema, "PKSampleSourcesafe, stationCode, altm, date, dew, dir, gus, hour, rh, spd, tmp, vis, weather", ptrPKSampleSourcesafe, ptrStationCode, ptrAltm, ptrDate, ptrDew, ptrDir, ptrGus, ptrHour, ptrRh, ptrSpd, ptrTmp, ptrVis, ptrWeather);

}
XMLNode* SampleSourcesafe::toViewXML()
{
	XMLNode* node = new XMLNode();
	XMLNode* hijo,* hijo1,* hijo2,* hijo3,* hijo4,* hijo5,* hijo6,* hijo7,* hijo8,* hijo9,* hijo10,* hijo11;
	hijo=hijo1=hijo2=hijo3=hijo4=hijo5=hijo6=hijo7=hijo8=hijo9=hijo10=hijo11=NULL;
	node->setNombre("record");
	
	//if(stationCode != "")
	//{	
		hijo = new XMLNode();
		hijo->setNombre("stationCode");
		hijo->setContenido(this->getStationCode());
		node->agregarHijo(hijo);
	//}
	//if(date != "")
	//{
		hijo1 = new XMLNode();
		hijo1->setNombre("date");
		hijo1->setContenido(this->getDate());
		node->agregarHijo(hijo1);
	//}
	//if(altm != "")
	//{
		hijo2 = new XMLNode();
		hijo2->setNombre("altm");
		hijo2->setContenido(this->getAltm());
		node->agregarHijo(hijo2);
//	}
	//if(dew != "")
	//{
		hijo3 = new XMLNode();
		hijo3->setNombre("dew");
		hijo3->setContenido(this->getDew());
		node->agregarHijo(hijo3);
//	}
//	if(dir != "")
//	{
		hijo4 = new XMLNode();
		hijo4->setNombre("dir");
		hijo4->setContenido(this->getDir());
		node->agregarHijo(hijo4);
	//}	
//	if(gus != "")
//	{
		hijo5 = new XMLNode();
		hijo5->setNombre("gus");
		hijo5->setContenido(this->getGus());
		node->agregarHijo(hijo5);
	//}	
//	if(rh != "")
	//{
		hijo6 = new XMLNode();
		hijo6->setNombre("rh");
		hijo6->setContenido(this->getRh());
		node->agregarHijo(hijo6);
//	}	
//	if(spd!="")
//	{
		hijo7 = new XMLNode();
		hijo7->setNombre("spd");
		hijo7->setContenido(this->getSpd());
		node->agregarHijo(hijo7);
//	}
//	if(tmp != "")
//	{
		hijo8 = new XMLNode();
		hijo8->setNombre("tmp");
		hijo8->setContenido(this->getTmp());
		node->agregarHijo(hijo8);
//	}	
//	if (vis != "")
//	{
		hijo9 = new XMLNode();
		hijo9->setNombre("vis");
		hijo9->setContenido(this->getVis());
		node->agregarHijo(hijo9);
//	}	
	//if(weather != "")
//	{
		hijo10 = new XMLNode();
		hijo10->setNombre("weather");
		hijo10->setContenido(this->getWeather());
		node->agregarHijo(hijo10);
		
		hijo11 = new XMLNode();
		hijo11->setNombre("hour");
		hijo11->setContenido(this->getHour());
		node->agregarHijo(hijo11);
//	}	
	return node;	
}
const SampleSourcesafe & SampleSourcesafe::operator=(const SampleSourcesafe& p)
{
	PKSampleSourcesafe = p.PKSampleSourcesafe;
	stationCode = p.stationCode;
	altm = p.altm;
	date = p.date;
	dew = p.dew;
	dir = p.dir;
	gus = p.gus;
	hour = p.hour;
	rh = p.rh;
	spd = p.spd;
	tmp = p.tmp;
	vis = p.vis;
	weather = p.weather;
	return (*this);
}

void SampleSourcesafe::print()
{
	std::cout << "PKSAMPLESOURCESAFE: " << PKSampleSourcesafe << std::endl;
	std::cout << "STATIONCODE: " << stationCode << std::endl;
	std::cout << "ALTM: " << altm << std::endl;
	std::cout << "DATE: " << date << std::endl;
	std::cout << "DEW: " << dew << std::endl;
	std::cout << "DIR: " << dir << std::endl;
	std::cout << "GUS: " << gus << std::endl;
	std::cout << "HOUR: " << hour << std::endl;
	std::cout << "RH: " << rh << std::endl;
	std::cout << "SPD: " << spd << std::endl;
	std::cout << "TMP: " << tmp << std::endl;
	std::cout << "VIS: " << vis << std::endl;
	std::cout << "WEATHER: " << weather << std::endl;
}

